package cn.stylefeng.guns.modular.gridsystem.controller;

import cn.hutool.core.lang.Dict;
import cn.stylefeng.guns.core.annotion.BusinessLog;
import cn.stylefeng.guns.core.enums.LogAnnotionOpTypeEnum;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.core.pojo.response.SuccessResponseData;
import cn.stylefeng.guns.modular.gridsystem.model.param.DirectoryTreeParam;
import cn.stylefeng.guns.sys.modular.dict.param.SysDictTypeParam;
import cn.stylefeng.guns.sys.modular.dict.service.SysDictTypeService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import cn.stylefeng.guns.modular.gridsystem.service.BizGatewayConfigTemplateService;
import cn.stylefeng.guns.modular.gridsystem.model.param.BizGatewayConfigTemplateParam;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 网关配置模板 控制器
 *
 * @author: ssy
 * @date: 2022/10/31 15:31
 */
@RestController
public class BizGatewayConfigTemplateController {

    @Resource
    private BizGatewayConfigTemplateService bizGatewayConfigTemplateService;

    @Resource
    private SysDictTypeService sysDictTypeService;

    /**
     * 分页查询网关配置模板
     *
     * @author ssy
     * @date 2022/10/31 15:31
     */
    @GetMapping("/bizGatewayConfigTemplate/page")
    @BusinessLog(title = "网关配置模板_分页查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData page(BizGatewayConfigTemplateParam bizGatewayConfigTemplateParam) {
        return new SuccessResponseData(bizGatewayConfigTemplateService.page(bizGatewayConfigTemplateParam));
    }

    /**
     * 获取全部网关配置模板
     *
     * @author ssy
     * @date 2022/10/31 15:31
     */
    @GetMapping("/bizGatewayConfigTemplate/list")
    @BusinessLog(title = "网关配置模板_查询所有", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list(BizGatewayConfigTemplateParam bizGatewayConfigTemplateParam) {
        return new SuccessResponseData(bizGatewayConfigTemplateService.list(bizGatewayConfigTemplateParam));
    }

    /**
     * 查看详情网关配置模板
     *
     * @author ssy
     * @date 2022/10/31 15:31
     */
    @GetMapping("/bizGatewayConfigTemplate/detail")
    @BusinessLog(title = "网关配置模板_查看详情", opType = LogAnnotionOpTypeEnum.DETAIL)
    public ResponseData detail(@Validated(BizGatewayConfigTemplateParam.detail.class) BizGatewayConfigTemplateParam bizGatewayConfigTemplateParam) {
        return new SuccessResponseData(bizGatewayConfigTemplateService.detail(bizGatewayConfigTemplateParam));
    }

    /**
     * 添加网关配置模板
     *
     * @author ssy
     * @date 2022/10/31 15:31
     */
    @PostMapping("/bizGatewayConfigTemplate/add")
    @BusinessLog(title = "网关配置模板_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated(BizGatewayConfigTemplateParam.add.class) BizGatewayConfigTemplateParam bizGatewayConfigTemplateParam) {
        bizGatewayConfigTemplateService.add(bizGatewayConfigTemplateParam);
        return new SuccessResponseData();
    }

    /**
     * 删除网关配置模板
     *
     * @author ssy
     * @date 2022/10/31 15:31
     */
    @PostMapping("/bizGatewayConfigTemplate/delete")
    @BusinessLog(title = "网关配置模板_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated(BizGatewayConfigTemplateParam.delete.class) BizGatewayConfigTemplateParam bizGatewayConfigTemplateParam) {
        bizGatewayConfigTemplateService.delete(bizGatewayConfigTemplateParam);
        return new SuccessResponseData();
    }

    /**
     * 编辑网关配置模板
     *
     * @author ssy
     * @date 2022/10/31 15:31
     */
    @PostMapping("/bizGatewayConfigTemplate/edit")
    @BusinessLog(title = "网关配置模板_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated(BizGatewayConfigTemplateParam.edit.class) BizGatewayConfigTemplateParam bizGatewayConfigTemplateParam) {
        bizGatewayConfigTemplateService.edit(bizGatewayConfigTemplateParam);
        return new SuccessResponseData();
    }

    /**
     * 修改状态
     *
     * @author ssy
     * @date 2022/10/31 15:31
     */
    @PostMapping("/bizGatewayConfigTemplate/changeStatus")
    @BusinessLog(title = "网关配置模板_修改状态", opType = LogAnnotionOpTypeEnum.CHANGE_STATUS)
    public ResponseData changeStatus(@RequestBody @Validated(BizGatewayConfigTemplateParam.changeStatus.class) BizGatewayConfigTemplateParam bizGatewayConfigTemplateParam) {
        bizGatewayConfigTemplateService.changeStatus(bizGatewayConfigTemplateParam);
        return new SuccessResponseData();
    }

    @GetMapping("/bizGatewayConfigTemplate/tree")
    public ResponseData tree() {
        final SysDictTypeParam sysDictTypeParam = new SysDictTypeParam();
        sysDictTypeParam.setCode("gateway_config_scene");
        final List<Dict> dicts = sysDictTypeService.dropDown(sysDictTypeParam);
        DirectoryTreeParam treeParam = new DirectoryTreeParam();
        treeParam.setId("000");
        treeParam.setTitle("全部场景");
        treeParam.setDisabled(true);
        treeParam.setKey("0-0");
        List<DirectoryTreeParam> treeParamList = new ArrayList<>();
        for (int i = 0; i < dicts.size(); i++) {
            DirectoryTreeParam treeParam1 = new DirectoryTreeParam();
            treeParam1.setId(dicts.get(i).get("code").toString());
            treeParam1.setTitle(dicts.get(i).get("value").toString());
            treeParam1.setDisabled(false);
            treeParam1.setKey(dicts.get(i).get("code").toString());
            treeParamList.add(treeParam1);
        }
        treeParam.setChildren(treeParamList);
        List<DirectoryTreeParam> treeParamList1 = new ArrayList<>();
        treeParamList1.add(treeParam);
        return new SuccessResponseData(treeParamList1);
    }

}
